<template>
  <Card class="login-card">
    <Form ref="formValidate" :model="formValidate" :rules="ruleValidate">
      <Form-item prop="user">
        <Input class="phone_input" type="text" v-model="formValidate.user" placeholder="输入账号" size="large">
          <Icon type="ios-person-outline" slot="prepend"></Icon>
        </Input>
      </Form-item>
      <Form-item prop="pwd">
        <Input class="phone_input" type="password" v-model="formValidate.pwd" placeholder="输入密码" size="large">
          <Icon type="ios-locked-outline" slot="prepend"></Icon>
        </Input>
      </Form-item>
      <Form-item>
        <Button long type="primary" @click="handleSubmit('formValidate')" size="large" class="phone_button">登陆</Button>
      </Form-item>
    </Form>

    <div class="login-footer">
      <Checkbox class="rememberme" v-model="single">记住我</Checkbox>
      <span class="forget">
        <router-link to="/forget">忘记密码?</router-link>
      </span>
    </div>
  </Card>
</template>

<script>
import { getUserName, getUserPwd, getUserGid } from '@/common/auth'
export default {
  data () {
    return {
      formValidate: {
        user: getUserName(),
        pwd: getUserPwd()
      },
      ruleValidate: {
        user: [{required: true, message: '账号不能为空', trigger: 'blur'}],
        pwd: [{required: true, message: '密码不能为空', trigger: 'blur'}]
      },
      single: true
    }
  },
  methods: {
    handleSubmit (fv) {
      this.$refs[fv].validate((valid) => {
        if (valid) {
          this.$store.dispatch('Login', this.formValidate).then(() => {
            let gid = getUserGid()
            console.log('login gid:', gid)
            if (gid + '' === '17') {
              console.log('login dashboardagent gid:', gid)
              this.$router.push({ path: '/dashboardagent' })
            } else {
              console.log('login dashboard gid:', gid)
              this.$router.push({ path: '/' })
            }
          }).catch(() => {
            console.log('login err')
          })
        } else {
          this.$Message.error('验证不成功')
        }
      })
    }
  }
}
</script>

<style>
 .login-card {
    margin: 210px auto;
  }
  .login-footer{
    margin-top: 10px;
    height: 10px;
    font-size: 30px;
  }
  .forget{
    float: right;
  }
  .rememberme{
    float: left;
    font-size: 30px;
  }
 .ivu-input-group-large .ivu-input{
    height: 100px;
    font-size: 50px;
  }
  .ivu-input-group{
    font-size: 50px;
  }
 .phone_input>.ivu-input-group-prepend{
    font-size: 50px;
 }
   .phone_button{
  height: 100px;
  font-size: 50px;
 }
.ivu-card-body{
  padding: 35px;
}
 
</style>
